<template>
  <div>
    <el-dialog :title="editTitle" :visible.sync="editOpen" width="80%" @closeAddUser="cancelForm" v-dialogDrag>
      <el-form :model="formData" label-width="140px" ref="editForm" size="small">
        <el-form-item label="订单编号" prop="projectNo">
          <el-input v-model="formData.projectNo" disabled />
        </el-form-item>
        <el-form-item label="工程名称" prop="gongchengName">
          <el-input v-model="formData.gongchengName" disabled />
        </el-form-item>
        <el-form-item label="客户名称" prop="customerName">
          <el-input v-model="formData.customerName" disabled />
        </el-form-item>
        <el-form-item label="业务员" prop="salesmanName">
          <el-input v-model="formData.salesmanName" disabled />
        </el-form-item>
        <el-form-item label="交货日期" prop="deliveryTime">
          <el-date-picker v-model="formData.deliveryTime" disabled type="date" value-format="yyyy-MM-dd" />
        </el-form-item>
        <el-form-item label="中标价" prop="goodsTaxUnitPrice">
          <el-input v-model="formData.goodsTaxUnitPrice" disabled />
        </el-form-item>
        <el-form-item label="产品编码" prop="goodsCode">
          <el-input v-model="formData.goodsCode" disabled />
        </el-form-item>
        <el-form-item label="产品名称" prop="goodsName">
          <el-input v-model="formData.goodsName" disabled />
        </el-form-item>
        <el-form-item label="产品型号" prop="goodModel">
          <el-input v-model="formData.goodModel" disabled />
        </el-form-item>
        <el-form-item label="产品状态" prop="status">
          <el-select v-model="formData.status" placeholder="请选择产品状态" disabled>
            <el-option
              v-for="item in dict.type.goods_status"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="计量单位" prop="unit">
          <el-input v-model="formData.unit" disabled />
        </el-form-item>
        <el-form-item label="是否自制" prop="isdo" >
          <el-select v-model="formData.isdo" placeholder="请选择是否自制" disabled>
            <el-option
              v-for="item in dict.type.isdo"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="请购/自制数量" prop="pleaseBuyCount">
          <el-input-number v-model="formData.pleaseBuyCount" type="number"/>
        </el-form-item>
        <el-form-item label="采购数量(总库存)" prop="count">
          <el-input v-model="formData.count" disabled />
        </el-form-item>
        <el-form-item label="剩余库存(可用数量)" prop="remainderCount">
          <el-input v-model="formData.remainderCount" disabled />
        </el-form-item>
        <el-form-item label="锁定数量" prop="lockCount">
          <el-input-number v-model="formData.lockCount" type="number"  />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="formData.remark" type="textarea" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">保存</el-button>
        <el-button @click="cancelForm">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { updateAction,getById } from '@/api/manage' // 假设 getAction 是用于发送请求的方法

export default {
  name: "ElseEditPleaseBuyFormList",
  dicts: ['goods_status', 'isdo'],
  props: {
  },
  data() {
    return {
        editTitle: "库管修改产品",
        formData:{
        },
        editOpen:false,
    };
  },
  methods: {
    opens(e) {
      this.formData = e;
      this.fetchGoodsOrderIn(e)
    },
    submitForm() {
        let that=this;
        updateAction('/goodsSaledo/goodsSaledo/kuguanEdit', that.formData).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.editOpen = false;
            this.$emit('ok');
        });
    },
    cancelForm() {
        this.editOpen = false;
    },
    fetchGoodsOrderIn(e) {
       getById('/goodsOrderIn/goodsOrderIn/',this.formData.goodsId).then(response => {
         //getById('/goodsSaledo/goodsSaledo/listGoodsOrderInById/',e.id).then(response => {
        // 处理查询结果
        this.formData.remainderCount = response.data.remainderCount
        this.formData.count = response.data.count
         //this.formData = response.data
         this.editOpen = true;
      }).catch(error => {
        console.error('查询失败', error);
      });
    }
  }
};
</script>
